import { renderFile } from 'ejs'
import { resolve } from 'path'
import { formatRules } from './delimiter'
import parseAttrs from './attrs'

export async function parsePreset (preset: any, dest = './') {
  const shape = preset.shape

  preset.$formatRules = formatRules
  preset.$parseAttrs = parseAttrs

  const code = await renderFile(resolve(__dirname, `../asset/${shape}/template.ejs`), preset)
  return { parser: 'vue', code, dest: resolve(dest, './temp.vue') }
}
